/**
 * 详情对话框
 */
var BtyZxHuopinFenleiInfoDlg = {
    data: {
        id: "",
        code: "",
        name: "",
        createUser: "",
        createTime: "",
        updateUser: "",
        updateTime: "",
        pid:"",
        pName:""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects','tree','layer'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;








    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/dgdZxHuopinFenlei/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('btyZxHuopinFenleiForm', result.data);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/dgdZxHuopinFenlei/editItem", function (data) {
            if(data.code==1){
                Feng.error("修改失败!" + data.message);
                return;
            }
            Feng.success("更新成功！");
            window.location.href = Feng.ctxPath + '/dgdZxHuopinFenlei';
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/dgdZxHuopinFenlei'
    });

    // 点击parent时
    $('#parent').click(function () {
        var formName = encodeURIComponent("parent.BtyZxHuopinFenleiInfoDlg.data.pName");
        var formId = encodeURIComponent("parent.BtyZxHuopinFenleiInfoDlg.data.pid");
        var treeUrl = encodeURIComponent("/dgdZxHuopinFenlei/tree");

        layer.open({
            type: 2,
            title: '父级名称',
            area: ['300px', '400px'],
            content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
            end: function () {
                $("#parentid").val(BtyZxHuopinFenleiInfoDlg.data.pid);
                $("#parent").val(BtyZxHuopinFenleiInfoDlg.data.pName);
            }
        });
    });


});